﻿package fj.ui
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import fj.events.FJEvent;
	
	public class FJPreload extends MovieClip
	{
		public var art:MovieClip;
		
		private var _percent:Number;
		
		public function FJPreload():void
		{
			addEventListener( Event.ENTER_FRAME, inLoop);
		}
		public function out():void
		{
			gotoAndPlay( "out:start" );
			removeEventListener( Event.ENTER_FRAME, inLoop );
			addEventListener( Event.ENTER_FRAME, outLoop );
		}
		public function set percent( n:Number ):void
		{
			_percent = n;
			art.gotoAndStop( Math.round( _percent ) );
			if(art.percent_txt != undefined){
				art.percent_txt.text = Math.round( _percent ) + "%";
			}
		}
		
		public function get percent():Number
		{
			return _percent;
		}
		private function inLoop( e:Event ):void
		{
			if( currentLabel == "in:end" ){
				gotoAndStop( "stand" );
				removeEventListener( Event.ENTER_FRAME, inLoop );
			}
		}
		private function outLoop( e:Event ):void
		{
			if( currentLabel=="out:end" ){
				stop();
				visible = false;
				removeEventListener( Event.ENTER_FRAME, outLoop );
				dispatchEvent( new FJEvent( FJEvent.OUT ) );
			}
		}
	}
}